// 导入状态管理组件 
import { createStore } from 'vuex'


// 创建一个新的 store 实例 
const store = createStore({
    state() {
        return {
            // 定义全局参数 
            collapse: true,
            // 记录登录用户信息的变量
            user: {
                username: "",
                password:"",
                salt: "https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png",
                nickName: "未刷新",
            },
            token: localStorage.getItem('token') ? localStorage.getItem('token') : null,
        }
    }, mutations: {
        // 设置参数改变规则 
        reverseCollapse(state: any) {
            state.collapse = !state.collapse
        },
        // 设置登录用户信息
        setUser(state, user) {
            state.user = user;
        },
        setToken (state,token) {
			state.token =token;
			localStorage.setItem("token",token);
		},
		delToken (state) {
			state.token = '';
			localStorage.removeItem("token");
		}
    }
})

// 默认导出模块 
export default store